package com.lyu.xiaolvshu.note.biz.rpc;

import com.lyu.framework.common.response.Response;
import com.lyu.xiaolvshu.user.api.UserFeignApi;
import com.lyu.xiaolvshu.user.dto.req.FindUserByIdReqDTO;
import com.lyu.xiaolvshu.user.dto.resp.FindUserByIdRespDTO;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Component;

import java.util.Objects;

@Component
public class UserRpcService {

    @Resource
    private UserFeignApi userFeignApi;

    public FindUserByIdRespDTO findById(Long userId) {
        FindUserByIdReqDTO findUserByIdReqDTO = FindUserByIdReqDTO.builder()
                        .id(userId)
                                .build();
        Response<FindUserByIdRespDTO> response = userFeignApi.findById(findUserByIdReqDTO);
        if (Objects.isNull(response) || !response.isSuccess()) {
            return null;
        }
        return response.getData();
    }
}
